#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int N;
	scanf("%d", &N);
	int i,j;
	int team, play, sore, team_sore[1000] = { 0 };
	for (i = 0; i < N; i++)
	{
		scanf("%d-%d %d", &team, &play, &sore);
		team_sore[team] += sore;
	}
	int champion = 0;
	int max = 0;
	for (i = 0; i < 1000; i++)
	{
		if (team_sore[i] > max)
		{
			max = team_sore[i];
			champion = i;
		}
	}
	printf("%d %d", champion, max);
	return 0;
}